Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add StudioSearch component #14348

Merged
merged 17 commits into from
Jan 13, 2025
Merged

Conversation

standeren
Copy link
Contributor

@standeren standeren commented Jan 3, 2025

Description

  • add StudioSearch component.
  • use new component in code list page in library.
  • use new component in text editor.
  • use new compone

Dashboard:
Skjermbilde 2025-01-06 kl  13 48 12
nt on dashboard.

Text-editor:
Skjermbilde 2025-01-06 kl  13 49 00

CodeLists in content library:
Skjermbilde 2025-01-06 kl  13 49 19

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new StudioSearch component to enhance search functionality across multiple pages.
    • Added clear search functionality to improve user experience.
  • Improvements

    • Updated search input selection to use more accessible role-based methods.
    • Refined layout and styling of search components.
    • Improved internationalization of search labels.
  • Refactoring

    • Replaced existing search components with a more consistent StudioSearch component.
    • Updated CSS classes and spacing using design system variables.

@github-actions github-actions bot added area/text-editor Area: Related to creating, translating and editing texts. solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 3, 2025
@standeren standeren added skip-releasenotes Issues that do not make sense to list in our release notes area/content-library Area: Related to library for shared resources team/studio-domain1 skip-documentation Issues where updating documentation is not relevant labels Jan 3, 2025
@TomasEng TomasEng self-assigned this Jan 3, 2025
@TomasEng TomasEng assigned standeren and unassigned TomasEng Jan 3, 2025
@ErlingHauan
Copy link
Contributor

Vi har et søkefelt på dashbordet også. Hvis det ikke er for mye jobb, kan du legge den til der i tillegg?

@github-actions github-actions bot added the area/dashboard Area: Related to the dashboard application label Jan 3, 2025
@github-actions github-actions bot added the quality/testing Tests that are missing, needs to be created or could be improved. label Jan 6, 2025
Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.66%. Comparing base (683992b) to head (9fe3f1a).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14348   +/-   ##
=======================================
  Coverage   95.66%   95.66%           
=======================================
  Files        1871     1873    +2     
  Lines       24287    24297   +10     
  Branches     2788     2789    +1     
=======================================
+ Hits        23233    23244   +11     
  Misses        797      797           
+ Partials      257      256    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@standeren standeren assigned TomasEng and unassigned standeren Jan 6, 2025
@TomasEng TomasEng self-requested a review January 6, 2025 08:34
@TomasEng TomasEng assigned standeren and unassigned TomasEng Jan 6, 2025
Copy link
Contributor

@ErlingHauan ErlingHauan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

Dashboard

Label er over søkefeltet i PR-beskrivelsen, men ser det nå står til venstre:
bilde

Språk

Label kommer helt inntil tekstfeltet når det er fokusert. Kan du gjøre avstanden litt større?
bilde

Bibliotek

Her har label havnet til venstre for tekstfelt, og ser i PR-beskrivelsen at den skal være over feltet.
bilde

Edit: fjernet en bolk som angikk feil konfig av .env hos meg 😅

@ErlingHauan ErlingHauan assigned standeren and unassigned ErlingHauan Jan 13, 2025
@standeren standeren force-pushed the add-studio-component-for-search branch from 8efefb3 to 3cfe28c Compare January 13, 2025 13:59
@standeren standeren assigned ErlingHauan and unassigned standeren Jan 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (4)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1)

13-22: Consider adding aria-label when no visible label is present.

While the implementation looks good, consider adding an aria-label when showLabel is false to maintain accessibility.

 return (
   <div>
     {showLabel && (
       <Label htmlFor={searchId} spacing>
         {label}
       </Label>
     )}
-    <Search {...rest} id={searchId} size={size} ref={ref} />
+    <Search 
+      {...rest} 
+      id={searchId} 
+      size={size} 
+      ref={ref}
+      aria-label={!showLabel && label ? label : undefined}
+    />
   </div>
 );
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.test.tsx (1)

22-27: Add test for aria-label when no visible label is present.

To ensure accessibility is maintained, add a test case for the aria-label when showLabel is false.

+ it('should have aria-label when visible label is not shown', () => {
+   const label = 'Search for something';
+   renderTestSearch({ label, showLabel: false });
+   const search = screen.getByRole('searchbox', { name: label });
+   expect(search).toHaveAttribute('aria-label', label);
+ });
frontend/testing/playwright/pages/DashboardPage.ts (1)

96-96: Consider adding a name to the searchbox role selector.

While using getByRole('searchbox') follows accessibility best practices, adding the expected label text would make the test more specific and robust.

-    await this.page.getByRole('searchbox').fill(word);
+    await this.page.getByRole('searchbox', { name: this.textMock('dashboard.search') }).fill(word);
frontend/dashboard/pages/Dashboard/Dashboard.module.css (1)

6-7: Consider enhancing responsive layout

While the grid layout works, consider these improvements for better responsiveness:

  • Add media queries for narrow viewports
  • Define minimum column widths
  • Consider fallback for older browsers

Example improvement:

 .topBar {
   display: grid;
-  grid-template-columns: auto auto;
+  grid-template-columns: minmax(200px, 1fr) minmax(auto, max-content);
   justify-content: space-between;
   align-items: center;
   margin-bottom: var(--fds-spacing-10);
+  gap: var(--fds-spacing-4);
+  @media (max-width: 768px) {
+    grid-template-columns: 1fr;
+    gap: var(--fds-spacing-6);
+  }
 }

Also applies to: 55-55

🛑 Comments failed to post (1)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeListsActionsBar/CodeListsActionsBar.tsx (1)

38-41: 💡 Codebase verification

Missing required controlled component props

The StudioSearch component requires controlled component implementation as evidenced by other usages in the codebase (e.g., in TextEditor.tsx and Dashboard.tsx). The current implementation should include:

  • value prop for controlled state
  • onChange handler for input changes
🔗 Analysis chain

Missing search functionality props.

The StudioSearch component appears to be missing essential props for search functionality:

  • onChange handler for search input
  • value prop for controlled input
  • placeholder for better UX when label is visible
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if search functionality is implemented elsewhere
rg -A 5 "StudioSearch.*onChange" .

Length of output: 36


Script:

#!/bin/bash
# Find StudioSearch component definition
fd StudioSearch

Length of output: 237


Script:

#!/bin/bash
# Look for any StudioSearch usage patterns
rg "StudioSearch" -A 3

Length of output: 6543


Script:

#!/bin/bash
# Find component imports
rg "import.*StudioSearch"

Length of output: 711

@standeren
Copy link
Contributor Author

Test

Dashboard

Label er over søkefeltet i PR-beskrivelsen, men ser det nå står til venstre: bilde

Språk

Label kommer helt inntil tekstfeltet når det er fokusert. Kan du gjøre avstanden litt større? bilde

Bibliotek

Her har label havnet til venstre for tekstfelt, og ser i PR-beskrivelsen at den skal være over feltet. bilde

Edit: fjernet en bolk som angikk feil konfig av .env hos meg 😅

Ups, bra vi tester si 😉 Har skjedd under kodegjennomgang - fikset nå!

Copy link
Contributor

@ErlingHauan ErlingHauan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ser bra ut 🥳

@ErlingHauan ErlingHauan assigned standeren and unassigned ErlingHauan Jan 13, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1)

14-14: Consider enhancing className handling.

The className prop is directly passed to the wrapper div. Consider using a utility like clsx or classnames to combine multiple class names and ensure robust handling of undefined or null values.

-      <div className={className}>
+      <div className={clsx(className)}>

Don't forget to add the import:

import clsx from 'clsx';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8efefb3 and 7bc2dea.

📒 Files selected for processing (4)
  • frontend/dashboard/pages/Dashboard/Dashboard.module.css (0 hunks)
  • frontend/dashboard/pages/Dashboard/Dashboard.tsx (2 hunks)
  • frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (1 hunks)
  • frontend/packages/text-editor/src/TextEditor.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • frontend/dashboard/pages/Dashboard/Dashboard.module.css
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/dashboard/pages/Dashboard/Dashboard.tsx
  • frontend/packages/text-editor/src/TextEditor.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
  • GitHub Check: CodeQL
🔇 Additional comments (4)
frontend/libs/studio-components/src/components/StudioSearch/StudioSearch.tsx (4)

1-5: LGTM! Clean imports and type definitions.

The imports are well-organized, and the WithoutAsChild utility is used appropriately to define the component's props type.


7-24: LGTM! Well-structured component implementation.

The component follows React best practices with proper ref forwarding, ID generation, and label accessibility.


26-28: LGTM! Proper component naming and export.

The displayName is set correctly for debugging purposes, and the export follows the standard pattern.


1-28: Verify integration points across the application.

Since this component replaces existing search implementations in multiple places (dashboard, text editor, code list page), let's verify the integration points:

✅ Verification successful

Integration verification successful

The StudioSearch component is properly integrated across all intended locations (dashboard, text editor, code list page) with consistent implementation patterns. No direct usage of the base Search component remains in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify StudioSearch component usage across the application

# Check import statements
echo "Checking StudioSearch imports:"
rg -l "import.*StudioSearch" --type ts --type tsx

# Check component usage
echo "\nChecking StudioSearch component usage:"
rg "<StudioSearch" --type tsx -A 3

# Check for any remaining old search implementations
echo "\nChecking for potential remaining old implementations:"
rg -l "import.*Search.*from.*@digdir/designsystemet-react" --type ts --type tsx

Length of output: 537


Script:

#!/bin/bash
# Description: Verify StudioSearch component usage with corrected syntax

echo "Checking StudioSearch imports:"
rg "import.*StudioSearch" -g "*.{ts,tsx}"

echo -e "\nChecking StudioSearch component usage:"
rg "<StudioSearch" -g "*.tsx" -A 3

echo -e "\nChecking for potential remaining old Search implementations:"
rg "import.*Search.*from.*@digdir/designsystemet-react" -g "*.{ts,tsx}"

Length of output: 3428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/content-library Area: Related to library for shared resources area/dashboard Area: Related to the dashboard application area/text-editor Area: Related to creating, translating and editing texts. frontend quality/testing Tests that are missing, needs to be created or could be improved. skip-documentation Issues where updating documentation is not relevant skip-releasenotes Issues that do not make sense to list in our release notes solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain1
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants